package com.server.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mono;

/**
 * @ClassName: RedisRateLimiterConfig
 * @Description: 限流配置类
 * @Author yza
 * @Date 2022/5/31 10:15
 * @Version V1.0
 */
@Configuration
@Primary
public class RedisRateLimiterConfig{

    /**
     * 限流
     * @author LXC
     * @date 2022/6/10 7:49
     */
    @Bean
    public KeyResolver ipKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
    }

}
